package com.yonyou.struts2demo.getformdata;

import com.opensymphony.xwork2.ActionSupport;
import com.yonyou.struts2demo.form.User;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author wwj
 * @Date 2021/12/12
 * @Description 第一种，原始方式获取表单封装到实体类对象
 */
public class GetFormEntityAction extends ActionSupport {

    @Override
    public String execute() throws Exception {

        // 1 获取表单数据
        HttpServletRequest request = ServletActionContext.getRequest();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String address = request.getParameter("address");

        // 2 封装到实体类对象里面
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setAddress(address);

        System.out.println("user = " + user);
        return NONE;
    }
}
